package deng.hibernate.test;

import java.sql.SQLException;

import oracle.jdbc.OracleTypes;

import org.hibernate.HibernateException;
import org.hibernate.dialect.Oracle10gDialect;
import org.hibernate.util.ReflectHelper;

/**
This bug is due to Oracle deprecated their oracle.jdbc.driver package
and Hibernate is still using it uptil 3.3.2.GA. Use this workaround
if you can't upgrade.
*/
public class OracleCursorTypeFixedDialect extends Oracle10gDialect {
	int oracletypes_cursor_value = 0;
	@Override
	public int registerResultSetOutParameter(java.sql.CallableStatement statement,int col) throws SQLException {
		if(oracletypes_cursor_value==0) {
			try {
//				Class types = ReflectHelper.classForName("oracle.jdbc.OracleTypes");
//				oracletypes_cursor_value = types.getField("CURSOR").getInt(types.newInstance());
				
				oracletypes_cursor_value = OracleTypes.CURSOR;
			} catch (Exception se) {
				throw new HibernateException("Problem while trying to load or access OracleTypes.CURSOR value",se);
			}
		}
		//	register the type of the out param - an Oracle specific type
		statement.registerOutParameter(col, oracletypes_cursor_value);
		col++;
		return col;
	}
}
